package com.zhijiaoyun.service.impl;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhijiaoyun.dao.IRECourseCategoryDao;
import com.zhijiaoyun.service.IRECourseCategoryService;

/**
 * @author shisfish
 * @date 2017/6/6
 */
@Service(value = "reCourseCategoryService")
public class RECourseCategoryServiceImpl implements IRECourseCategoryService {

	@Resource
	IRECourseCategoryDao reCourseCategoryDao;
	
	@Override
	public void addRECourseCategory(Long courseId, String categoryIds) {
		
		// 把之前的关系表都删除
		reCourseCategoryDao.deleteByCourseId(courseId);
		
		List<String> categoryList = Arrays.asList(categoryIds.split("/"));
//		for (String string : categoryList) {
			reCourseCategoryDao.insert(courseId, Long.parseLong(categoryList.get(categoryList.size() - 1)));
//		}
	}

	@Override
	public int countByCategoryids(List<Long> categoryids) {
		return reCourseCategoryDao.countByCategoryids(categoryids);
	}

	@Override
	public int countByCategoryId(Long categoryId) {
		return reCourseCategoryDao.countByCategoryId(categoryId);
	}

}
